//
//  GlobalKeys.h
//  MUGH
//
//  Created by iwind on 15/2/9.
//  Copyright (c) 2015年 MUGH. All rights reserved.
//

#ifndef MUGH_GlobalKeys_h //如果没有定义则执行
#define MUGH_GlobalKeys_h //定义，防止重复定义，与上面语句配合

#define IPHONE_X \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})

#define ScreenWidth    [UIScreen mainScreen].bounds.size.width

#define Parameter   (([[UIScreen mainScreen] bounds].size.width > 375) ? 0.55 : 0.5)

#define ScreenHeight   [UIScreen mainScreen].bounds.size.height

#define RGBOF(rgbValue)     [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 \
alpha:1.0]

#define URL_BASE_8018 @"https://qyi.careate.cn/"

#define kDevice_Is_iPhoneX ([UIApplication sharedApplication].statusBarFrame.size.height >= 44 ? YES : NO)

#define App_Build  [NSString stringWithFormat:@"%@",[[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"]]

#define GetVersionInfoRedis [NSString stringWithFormat:@"%@api/ApiVersion/GetVersionInfoRedis",URL_BASE_8018]

#define DebugLog(format, ...)  NSLog(format, ## __VA_ARGS__)

#define DeBugLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#define UnZipPassWord  @"sdjfglaf?fajsi"


//坐标相关
#define Main_Screen_Height      [[UIScreen mainScreen] bounds].size.height
#define Main_Screen_Width       [[UIScreen mainScreen] bounds].size.width

#define SL_kScreenWidth [UIScreen mainScreen].bounds.size.width
#define SL_kScreenHeight [UIScreen mainScreen].bounds.size.height

#define Frame_Width       [UIScreen mainScreen].bounds.size.width
#define Frame_HEIGHT      [UIScreen mainScreen].bounds.size.height

///主线程操作
#define SL_DISPATCH_ON_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(),mainQueueBlock);
#define SL_GCDWithGlobal(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define sl_GCDWithMain(block) dispatch_async(dispatch_get_main_queue(),block)

/// 弱引用对象
#define SL_WeakSelf __weak typeof(self) weakSelf = self;

#define   kLeftMenuReveal 276

#define  PAT_WWW_FOLDER_NAME    @"Customer"
#define  NURSE_WWW_FOLDER_NAME  @"NetWorkNurse"

//屏幕适配 之 安全区域
#define StatusBarHeight   (Main_Screen_Height >= 812.0 ? 44 : 20)
#define SafeAreaTopHeight (Main_Screen_Height >= 812.0 ? 88 : 64)
#define SafeNavHeight (Main_Screen_Height >= 812.0 ? 64 : 44)
#define safeAreaHeightTabBar (Main_Screen_Height >= 812.0 ? 83 : 49)
#define SafeAreaBottomHeight (Main_Screen_Height >= 812.0 ? 34 : 0)
#define SafeAreaHeightWithNav Main_Screen_Height - SafeAreaTopHeight - SafeAreaBottomHeight
#define SafeAreaHeightWithBottom Main_Screen_Height - SafeAreaTopHeight
#define SafeAreaHeightWithNavAndToolbar Main_Screen_Height - SafeAreaTopHeight - SafeAreaBottomHeight

#define DrawerScale (([[UIScreen mainScreen] nativeScale]>2) ? 1.2 : 1)
//抽屉宽度
#define DRAWER_WIDTH Main_Screen_Width*2/3


//RGB 设置颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

#define COLOR_R_G_B_A(r,g,b,a)   [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

//Current device Information

#define kDeviceModel [[UIDevice currentDevice]model]
#define KDeviceSystemName [[UIDevice currentDevice]systemName]
#define kDeviceSystemVersion [[UIDevice currentDevice]systemVersion]
#define kDeviceUUID [[UIDevice currentDevice]identifierForVendor]UUIDString]
#define kAppVersion  [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

// CID 转 环信ID


#define WEAK_SELF(weakSelf)  __weak __typeof(&*self)weakSelf = self

//2.1-AppStore的版本地址
#define KUrl_UPDateAPPSTORE  @"https://itunes.apple.com/lookup?id="

#define IS_DISTRIBUTION 0

#ifdef DEBUG
// 开发测试环境

#define EM_APNS_CER_NAME @"QYi_AppDev_APNS"

#define SHOW_QC_MESSAGE 1

#else
//正式环境

#define DeBugLog(...)

#define SHOW_QC_MESSAGE 0
#endif

#define ALERT_THREE(msg) [[[UIAlertView alloc]initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil] show];
#define ALERT_ONE(msg) [[[UIAlertView alloc]initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil] show];
//消息名称
#define USER_IDCARD_INFO_CONFRIMED @"UserIDCardInfoConfirmed"
#define HIDE_POPALERT_VIEW @"HidePopAlertView"
#define PUSH_NOTIFICATION_CHANGED @"pushNotificationChanged"
#define PREVIEW_DISMISSED @"previewDismissed"
#define USER_LOGIN @"userLogin"
#define UPLOAD_USER_LOG @"UPLOAD_USER_LOG"
/************************* NSUserDefults  存取 ****************************/
#define SET_USERDEFULTS_OBJC(objc,keys)\
if(objc && keys){ \
[[NSUserDefaults standardUserDefaults] setObject:objc forKey:keys]; \
[[NSUserDefaults standardUserDefaults] synchronize]; \
}

#define SET_DOUBLE_DEFULTS(obj,key)\
if(key){ \
[[NSUserDefaults standardUserDefaults] setDouble:obj forKey:key]; \
[[NSUserDefaults standardUserDefaults] synchronize]; \
}
#define SET_BOOL_DEFULTS(obj,key)\
if(obj && key){ \
[[NSUserDefaults standardUserDefaults] setBool:obj forKey:key]; \
[[NSUserDefaults standardUserDefaults] synchronize]; \
}

#define GET_DOUBLE_DEFULTS(key) (key ? [[NSUserDefaults standardUserDefaults] doubleForKey:key] : 0)
#define GET_USERDEFULTS(key) (key ? [[NSUserDefaults standardUserDefaults] stringForKey:key] : @"")
#define GET_OBJECT_KEY(key)    (key ? [[NSUserDefaults standardUserDefaults] objectForKey:key] : nil)
#define GET_BOOL_KEY(key)    (key ? [[NSUserDefaults standardUserDefaults] boolForKey:key] : NO)

#define REMOVE_DRFULTS(key) { [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];\
[[NSUserDefaults standardUserDefaults] synchronize]; \
}

// 新版热更新 加密文件（main.js.zip   main.css.zip  vendor.js.zip）解压密码
#define UnZipPassWord  @"careate2020!zip"
//文件路径
#define USER_INFO_SERVER_NAME @"DeviceUUID"
#define UUID_KEY @"UUID_Key"
#define MSG_EXT_MedicalRecord  @"em_medicalRecord"
#define LOCAL_BUILD_VERSION @"LocalBuildVersion"

#define EXCEPTION_KEY @"EXCEPTION_Key"
#define CALL_STACK_SYMBOLS_KEY @"callStackSymbols_Key"

#define NAVIGATION_BAR_HEIGHT (kDevice_Is_iPhoneX ? 88:64)
#define SCREEN_RATIO                    SCREEN_WIDTH/375  /**<屏幕的宽比  基准375*/

#define SCREEN_WIDTH  ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT  ([[UIScreen mainScreen] bounds].size.height)

#define SCALE_WIDTH(w) (SCREEN_WIDTH/320.0*w)
#define SCALE_HEIGHT(h) (SCREEN_HEIGHT/480.0*h)

#define ScaleWidth(w) ([UIScreen mainScreen].bounds.size.width / 375*w)
#define ScaleHeight(h) ([UIScreen mainScreen].bounds.size.height / 568.0*h)

#define RECTFIX_WIDTH(a) (IS_IPHONE6 ? a : ScaleWidth(a))
#define RECTFIX_HEIGHT(a) (IS_IPHONE6 ? a : ScaleHeight(a))

#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]

#define IS_IPHONE4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_IPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_IPHONE6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_IPHONE6_PLUS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_iPhoneX [UIScreen mainScreen].bounds.size.height >= 812.0

#define APPLICATION ((AppDelegate *)[[UIApplication sharedApplication] delegate])

// not UIUserInterfaceIdiomPad
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
// detect iPhone6 Plus based on its native scale

#define FontScale 1

#define XL_Weak __block __weak __typeof(self) weakSelf = self

//RGB 设置颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
//状态栏颜色
#define  STATUS_BAR_COLOR RGBA(106, 137, 165, 1)

//导航栏颜色
#define  NAVI_BAR_COLOR RGBA (106, 137, 165, 1)
#define  MsgCellSepColor RGBOF(0xebedf0)
#define SYSTEMFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE]

// 导航栏颜色 天蓝色
#define NAVI_BAR_SKYBLUE RGBOF(0x6C9AF3)



#define autoSizeScaleX  (Main_Screen_Width>320?Main_Screen_Width/320:1)
#define autoSizeScaleY  (Main_Screen_Height>568?Main_Screen_Height/568:1)

// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

#define IOS10_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0)

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

//
//文件名相关
#define USER_LOGIN_DATA_SAVE_PATH @"UserLoginDataSavePath"
#define USER_BASIC_MESSAGE_DATA_SAVE_PATH @"UserBasicMessageDataSavePath"
#define USER_TOKEN_OBTAIN_TIME @"UserObtainTime"//用户获取token时间
#define PATIENTS_INFO_SAVE_PATH @"PatientsInfoSavePath"//用户CID对应的PID用户
#define ENTER_BACK_GROUND_TIME @"EnterBackGroundTime"//用户CID对应的PID用户
#define AI_SERVICE_UNREAD_COUNT @"AIServiceUnreadMessagesCount"

//应用变量
#define USER_LOGIN_MODEL ((QHUserLoginModel*)[[NSUserDefaults standardUserDefaults]rm_customObjectForKey:USER_LOGIN_DATA_SAVE_PATH])
#define AUTH_TOKEN [NSString stringWithFormat:@"%@ %@",@"Bearer",[QHCommonTool getUserInfoFromDB].access_token]
#define GET_CHATID [USER_LOGIN_MODEL.cid stringByReplacingOccurrencesOfString:@"-" withString:@""]

#define isCID_NULL ([SecurityStorage getString:@"cid"] == NULL ? YES : NO)

#define USER_CID  (isCID_NULL ? @"" : [SecurityCipher decryptString:[SecurityStorage getString:@"cid"] key:[UserInfoTool SDKToken]])

#endif
